from multiprocessing import Process, Queue

from wechat_pc_api.wechat import WeChatManager

wechat_manager = WeChatManager(libs_path='./libs')

import time
import datetime

to_wxid = "Angel-baby-lover"


def msg_consumer(q):
    """
    消息队列消费者

    :param q:
    :return:
    """
    wechat_manager.manager_wechat(smart=True)
    while True:
        if not q.empty():
            message = q.get()
            wechat_manager.send_text(1, to_wxid, '{} {}'.format(message, time.time()))


def prod(q):
    while True:
        q.put("测试消息 {}".format(datetime.datetime.now().strftime('%H:%M:%S')))
        time.sleep(2)


if __name__ == '__main__':
    # 添加回调实例对象
    q = Queue(36)
    pr = Process(target=prod, args=(q,))
    cu = Process(target=msg_consumer, args=(q,))
    pr.start()
    cu.start()
    while True:
        time.sleep(2)
